package com.itheima.tliasproject.aop;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Slf4j
@Component
public class AspectTime  {

    @Around("execution(* com.itheima.tliasproject.service.impi.DeptServiceImpI.*(..))")
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable{
        //1.获取方法运行时的开始时间
        Long begin =  System.currentTimeMillis();

        //2.运行原始方法
        Object result = joinPoint.proceed();

        //3.获取方法结束时间，计算耗时
        Long end = System.currentTimeMillis();

        log.info("当前耗时是：{} ms",end - begin);

        return result;
    }
}
